import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yp/helper.dart';
import 'package:yp/pages/mall_app/turntable/state.dart';
import 'package:yp/pages/mall_app/turntable_aword/logic.dart';

class TurntableBriefView extends StatelessWidget {
  TurntableBriefView({Key key}) : super(key: key);
  final TurntableState state = Get.find<TurntableAwardLogic>().state.infoState;

  String _getAwardBrief() {
    String str = '';

    state.bingoRewardConfigure.forEach((e) {
      str +=
          ((e['reward_level'] ?? '') + '：' + (e['reward_name'] ?? '') + '\n');
    });
    return str.substring(0, str.length - 1);
  }

  String _getTime() {
    return state.basicInfo['valid_begin_dtme'] +
        '至' +
        state.basicInfo['valid_end_dtme'];
  }

  String _getRule() {
    var info = state.drawConfigure;
    String str = '';
    int limitType = info['activity_draw_limit_type'];
    var limitContent = '';
    if (limitType == 0) {
      limitContent = '不限制';
    } else if (limitType == 1) {
      limitContent = '每人最多' + '${info['activity_draw_limit']}' + '次';
    } else if (limitType == 2) {
      limitContent = '每人每日最多' + '${info['activity_draw_limit']}' + '次';
    }
    str = '活动次数：' + limitContent + '\n';

    int freeDrawType = info['activity_free_draw_limit_type'];
    var freeDrawContent = '';
    if (freeDrawType == 0) {
      freeDrawContent = '不限制';
    } else if (freeDrawType == 1) {
      freeDrawContent = '每人最多' + '${info['activity_free_draw_limit']}' + '次';
    } else if (freeDrawType == 2) {
      freeDrawContent = '每人每日最多' + '${info['activity_free_draw_limit']}' + '次';
    }
    str += ('免费抽奖次数：') + freeDrawContent + '\n';
    if (info['activity_draw_exchange_type'] == 1) {
      str += ('兑换抽奖次数：') + '\n';
      String exchangeContent = '';
      var drawInfo = state.drawExchangeConfigure;
      if (drawInfo['integral_exchange_flag'] == 1) {
        exchangeContent = '每消耗' +
            '${drawInfo['integral_exchange_cost']}' +
            '积分可以兑换一次机会，积分兑换每日上限' +
            '${drawInfo['integral_exchange_limit']}';
        str += exchangeContent;
      }
      if (drawInfo['share_reward_flag'] == 1) {
        exchangeContent = '每次分享奖励抽奖次数' +
            '${drawInfo['share_reward']}' +
            ',分享奖励每日上限' +
            '${drawInfo['share_reward_limit']}';
        str += exchangeContent;
      }

      if (drawInfo['purchase_reward_flag'] == 1) {
        exchangeContent = '下单金额大于' +
            '${drawInfo['purchase_reward_boundary']}' +
            '元后获得' +
            '${drawInfo['purchase_reward']}' +
            '次机会';
        if (drawInfo['purchase_reward_limit'] > 0) {
          var _content = '每日最多' + '${drawInfo['purchase_reward_limit']}' + '次';
          exchangeContent += _content;
        }
        str += exchangeContent;
      }
    }
    return str;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        _getCell('活动奖品', _getAwardBrief()),
        _getCell('活动时间', _getTime()),
        _getCell('活动规则', _getRule()),
        _getCell('活动人群',
            state.basicInfo['participant_group_limit_display_name'] ?? '所有用户'),
        _getCell('活动说明', state.basicInfo['activity_description']),
      ],
    );
  }

  Widget _getCell(String title, String content) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Container(
              height: setWidth(28),
              width: setWidth(8),
              decoration: BoxDecoration(
                  borderRadius: BorderRadiusDirectional.circular(setWidth(4)),
                  gradient: LinearGradient(
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [Color(0xffF5515F), Color(0xff9F041B)])),
            ),
            SizedBox(
              width: setWidth(20),
            ),
            Text(
              title,
              style:
                  TextStyle(color: Color(0xff222222), fontSize: setWidth(32)),
            )
          ],
        ),
        SizedBox(
          height: setWidth(20),
        ),
        Text(
          content,
          style: TextStyle(color: Color(0xff666666), fontSize: setWidth(26)),
        ),
        SizedBox(
          height: setWidth(50),
        ),
      ],
    );
  }
}
